<template>
  <el-dialog
    :title="!dataForm.docBankId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="医生账号外键id" prop="docId">
      <el-input v-model="dataForm.docId" placeholder="医生账号外键id"></el-input>
    </el-form-item>
    <el-form-item label="持卡人（医生姓名）" prop="docName">
      <el-input v-model="dataForm.docName" placeholder="持卡人（医生姓名）"></el-input>
    </el-form-item>
    <el-form-item label="身份证号" prop="idNumber">
      <el-input v-model="dataForm.idNumber" placeholder="身份证号"></el-input>
    </el-form-item>
    <el-form-item label="身份证有效期" prop="cardIndate">
      <el-input v-model="dataForm.cardIndate" placeholder="身份证有效期"></el-input>
    </el-form-item>
    <el-form-item label="银行卡号" prop="bankCard">
      <el-input v-model="dataForm.bankCard" placeholder="银行卡号"></el-input>
    </el-form-item>
    <el-form-item label="手机号" prop="dockerPhoe">
      <el-input v-model="dataForm.dockerPhoe" placeholder="手机号"></el-input>
    </el-form-item>
    <el-form-item label="银行预留手机号" prop="bankPhone">
      <el-input v-model="dataForm.bankPhone" placeholder="银行预留手机号"></el-input>
    </el-form-item>
    <el-form-item label="银行名称" prop="bankName">
      <el-input v-model="dataForm.bankName" placeholder="银行名称"></el-input>
    </el-form-item>
    <el-form-item label="银行卡密码" prop="bankPassword">
      <el-input v-model="dataForm.bankPassword" placeholder="银行卡密码"></el-input>
    </el-form-item>
    <el-form-item label="卡中余额" prop="bankBalance">
      <el-input v-model="dataForm.bankBalance" placeholder="卡中余额"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          docBankId: 0,
          docId: '',
          docName: '',
          idNumber: '',
          cardIndate: '',
          bankCard: '',
          dockerPhoe: '',
          bankPhone: '',
          bankName: '',
          bankPassword: '',
          bankBalance: ''
        },
        dataRule: {
          docId: [
            { required: true, message: '医生账号外键id不能为空', trigger: 'blur' }
          ],
          docName: [
            { required: true, message: '持卡人（医生姓名）不能为空', trigger: 'blur' }
          ],
          idNumber: [
            { required: true, message: '身份证号不能为空', trigger: 'blur' }
          ],
          cardIndate: [
            { required: true, message: '身份证有效期不能为空', trigger: 'blur' }
          ],
          bankCard: [
            { required: true, message: '银行卡号不能为空', trigger: 'blur' }
          ],
          dockerPhoe: [
            { required: true, message: '手机号不能为空', trigger: 'blur' }
          ],
          bankPhone: [
            { required: true, message: '银行预留手机号不能为空', trigger: 'blur' }
          ],
          bankName: [
            { required: true, message: '银行名称不能为空', trigger: 'blur' }
          ],
          bankPassword: [
            { required: true, message: '银行卡密码不能为空', trigger: 'blur' }
          ],
          bankBalance: [
            { required: true, message: '卡中余额不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.docBankId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.docBankId) {
            this.$http({
              url: this.$http.adornUrl(`/aftersystem/docbank/info/${this.dataForm.docBankId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.docId = data.docBank.docId
                this.dataForm.docName = data.docBank.docName
                this.dataForm.idNumber = data.docBank.idNumber
                this.dataForm.cardIndate = data.docBank.cardIndate
                this.dataForm.bankCard = data.docBank.bankCard
                this.dataForm.dockerPhoe = data.docBank.dockerPhoe
                this.dataForm.bankPhone = data.docBank.bankPhone
                this.dataForm.bankName = data.docBank.bankName
                this.dataForm.bankPassword = data.docBank.bankPassword
                this.dataForm.bankBalance = data.docBank.bankBalance
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/aftersystem/docbank/${!this.dataForm.docBankId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'docBankId': this.dataForm.docBankId || undefined,
                'docId': this.dataForm.docId,
                'docName': this.dataForm.docName,
                'idNumber': this.dataForm.idNumber,
                'cardIndate': this.dataForm.cardIndate,
                'bankCard': this.dataForm.bankCard,
                'dockerPhoe': this.dataForm.dockerPhoe,
                'bankPhone': this.dataForm.bankPhone,
                'bankName': this.dataForm.bankName,
                'bankPassword': this.dataForm.bankPassword,
                'bankBalance': this.dataForm.bankBalance
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
